package jp.ne.hatena.d.digitalsoul.warikan.contexts

import java.util.Date

import jp.ne.hatena.d.digitalsoul.warikan.contexts.rootpopulaters._
import jp.ne.hatena.d.digitalsoul.warikan.models._
import jp.ne.hatena.d.digitalsoul.warikan.repositories._
import jp.ne.hatena.d.digitalsoul.warikan.roles._

class Planning extends PartyPopulater {
	
	var planner:Planner = null 
	
	var party:Party = null
	
	def setup(partyName:String, schedule:Date, location:String) = {
		
		val id:Int = PartyRepository.nextId
		val planner:Planner = new Party(id) with Planner
		
		planner.name = partyName
		planner.schedule = schedule
		planner.location = location
		
		this.planner = planner
		this.party =  planner.asInstanceOf[Party]
		
	}
	
	def populate(id:Int) = {
		
		val planner:Planner = new Party(id) with Planner 
		val party:Party = populateParty(planner)
		
		this.planner = planner
		this.party = party
		
	}
	
	def partyName:String = planner.name
	
	def schedule:Date = planner.schedule
	
	def location:String = planner.location
	
	def partyId:Int = planner.id
		
	def addPerticipant(name:String, role:String) = 
		planner.addParticipant(new Participant(name, role))
	
	def number:Int = planner.number
	
	def commit = PartyRepository.add(party) 
	
}